package web.listener;

import common.consts.Consts;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import web.utils.SpringUrlMappingUtil;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.Collection;

/**
 * Created by Ace Yin on 2015/5/29 0029.
 */
public class WebStartupListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent event) {
        ServletContext context = event.getServletContext();
        WebApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(context);
        Collection<SpringUrlMappingUtil.Mapping> mapping = SpringUrlMappingUtil.getMapping(appContext);
        context.setAttribute(Consts.SPRING_MVC_MAPPING_KEY, mapping);
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {

    }
}
